<%@page import="com.google.appengine.api.datastore.KeyFactory"%>
<%@page import="ua.org.energy.vkek.site.model.Article"%>
<%@page import="ua.org.energy.vkek.site.model.ArticleTag"%>
<%@page import="ua.org.energy.vkek.site.server.TagUtils"%>
<%@page import="ua.org.energy.vkek.site.model.ArticleCategory"%>
<%@page import="java.util.List"%>
<%@page import="ua.org.energy.vkek.site.server.EMF"%>
<%@page import="ua.org.energy.vkek.site.server.CategoryUtils"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <style type="text/css">
            div {
                border: yellowgreen dashed thin; 
                margin-top: 5px;
                margin-bottom: 5px;
                font: bold medium monospace;
                color: white;
                text-align: center;
            }
            .level1 {
                margin-left: 7px;
                background: blue;
            }
            .level2 {
                margin-left: 15px;
                background: green;
            }
            .level3 {
                margin-left: 23px;
                background: yellow;
                color: black;
            }
        </style>
    </head>
    <body>
        <%
            CategoryUtils cu = new CategoryUtils(EMF.getEM());

            List<ArticleCategory> cl = cu.listAll();
            for (ArticleCategory ac : cl) {
                out.println("<div class=\"level1\">");
                out.println("<p><a href=\"/s/" + KeyFactory.keyToString(ac.getIdent()) + "\">" + ac + "</a></p>");
                out.println("<div class=\"slider\">");
                List<ArticleTag> tl = ac.getArticleTags();
                for (ArticleTag at : tl) {
                    out.println("<div class=\"level2\">");
                    out.println("<p><a href=\"/s/" + KeyFactory.keyToString(ac.getIdent()) + "/" + KeyFactory.keyToString(at.getIdent()) + "\">" + at + "</a></p>");
                    out.println("<div class=\"slider\">");
                    List<Article> al = at.getArticles();
                    for (Article a : al) {
                        out.println("<div class=\"level3\">");
                        out.println("<p><a href=\"/s/" + KeyFactory.keyToString(ac.getIdent()) + "/"
                                + KeyFactory.keyToString(at.getIdent()) + "/" + KeyFactory.keyToString(a.getIdent()) + "\">" + a + "</a></p>");
                        out.println("</div>");
                    }
                    out.println("</div>");
                    out.println("</div>");
                }
                out.println("</div>");
                out.println("</div>");
            }

        %>
    </body>
</html>
